package cate.common.table.activity.throne;

import cate.common.table.ERow;
import cate.common.table.XSSFRowWrap;
import cate.common.table.d.GDThrone;
import easy.java.dev.note.NoteClass;
import org.apache.commons.lang3.StringUtils;

@NoteClass("选拔赛挑战")
public class TBTrialChallengeRow extends ERow {

    public int pointMin;
    public int pointMax;

    private int lowRwd;
    private int middleRwd;
    private int highRwd;

    private String lowRangeStr;
    private String middleRangeStr;
    private String highRangeStr;

    private String lowBotStr;
    private String middleBotStr;
    private String highBotStr;

    @Override
    public void parse(XSSFRowWrap xrw) {
        super.parse(xrw);
        id = xrw.getInteger("ID", 0);
        pointMin = xrw.getInteger("积分下限", 0);
        pointMax = xrw.getInteger("积分上限", 0);
        lowRwd = xrw.getInteger("初级积分", 0);
        middleRwd = xrw.getInteger("中级积分", 0);
        highRwd = xrw.getInteger("高级积分", 0);
        lowRangeStr = xrw.getString("初级范围");
        middleRangeStr = xrw.getString("中级范围");
        highRangeStr = xrw.getString("高级范围");

        lowBotStr = xrw.getString("初级bot等级范围");
        middleBotStr = xrw.getString("中级bot等级范围");
        highBotStr = xrw.getString("高级bot等级范围");
    }


    public int getRwdPoint(int level){
      switch (level){
          case GDThrone.TrialLevel.LOW: return lowRwd;
          case GDThrone.TrialLevel.MIDDLE:return middleRwd;
          case GDThrone.TrialLevel.HIGH:return highRwd;
          default:return 0;
      }
    }

    public Range getRankRange(int level){
        switch (level){
            case GDThrone.TrialLevel.LOW: return lowRankRange;
            case GDThrone.TrialLevel.MIDDLE:return middleRankRange;
            case GDThrone.TrialLevel.HIGH:return highRankRange;
            default:return null;
        }
    }

    public Range getRobotRange(int level){
        switch (level){
            case GDThrone.TrialLevel.LOW: return lowBotRange;
            case GDThrone.TrialLevel.MIDDLE:return middleBotRange;
            case GDThrone.TrialLevel.HIGH:return highBotRange;
            default:return null;
        }
    }


    public static class Range {

        public double start;
        public double end;

        public Range(String str) {
            if (StringUtils.isNotBlank(str)) {
                String[] split = str.split("#");
                if (split.length == 2) {
                    start = Double.parseDouble(split[0]);
                    end = Double.parseDouble(split[1]);
                }
            }
        }
    }

    private Range lowRankRange;
    private Range middleRankRange;
    private Range highRankRange;

    private Range lowBotRange;
    private Range middleBotRange;
    private Range highBotRange;


    @Override
    public void decode() {
        super.decode();
        lowRankRange = new Range(lowRangeStr);
        middleRankRange = new Range(middleRangeStr);
        highRankRange = new Range(highRangeStr);

        lowBotRange = new Range(lowBotStr);
        middleBotRange = new Range(middleBotStr);
        highBotRange = new Range(highBotStr);
    }
}
